package com.credit.jumu.calculator.activity;

import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.credit.jumu.calculator.R;
import com.credit.jumu.calculator.base.BaseActivity;
import com.credit.jumu.calculator.utils.LogUtils;
import com.credit.jumu.calculator.utils.StringHandleUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by Administrator on 2017/11/23/023.
 */
@EActivity(R.layout.activity_house_result)
public class HouseResultActivity extends BaseActivity {
	@ViewById
	TextView barheight, allHouseMoney, twotitle, oneShow, twoshow, threeshow, price1, price2, price3, price4;
	//契税
	double deedtax = 0;
	//营业税/综合地价款
	double salesTax = 0;
	//个人所得税
	double individualtax = 0;
	//房屋类型
	int houseType = 0;
	double houseArea = 0;//面积
	double nowprice = 0;//现价
	double oldprice = 0;//原价
	int houseLong = 0;//房屋时长
	boolean isFirstBuy = true;//是否首次
	boolean isOnlyBuy = false;//是否唯一

	@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
	@AfterViews
	public void initView() {

		Intent intent = getIntent();
		if (null == intent) {
			this.finish();
			return;
		}
		houseArea = intent.getDoubleExtra("houseArea", 0);
		nowprice = intent.getDoubleExtra("nowprice", 0);
		oldprice = intent.getDoubleExtra("oldprice", 0);
		houseType = intent.getIntExtra("houseType", 0);
		houseLong = intent.getIntExtra("houseLong", 0);
		isFirstBuy = intent.getBooleanExtra("isFirstBuy", true);
		isOnlyBuy = intent.getBooleanExtra("isOnlyBuy", true);
		initMoney();

		RelativeLayout.LayoutParams Params1 = (RelativeLayout.LayoutParams) barheight.getLayoutParams();
		Params1.height = getNavigationBarHeight();
		barheight.setLayoutParams(Params1);
		toAllWindow();
	}

	public void initMoney() {
		//契税
		double deedtax = 0;
		if (houseType != 1) {//普通、经济适用房
			if (isFirstBuy) {//首次购房
				if (houseArea <= 90) {
					deedtax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.01);
					oneShow.setText("首次购房且面积≤90㎡，契税为总房价的1%");
				} else {
					deedtax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.015);
					oneShow.setText("首次购房且>90㎡，契税为总房价的1.5%");
				}
			} else {//非首次购买
				deedtax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.03);
				oneShow.setText("非首次购买，契税为总房价的3%");
			}

		} else {//非普通、经济适用房
			if (isFirstBuy) {//首次购房
				deedtax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.015);
				oneShow.setText("首套非普通住宅，契税为总房价的1.5%");
			} else {//非首次购买
				deedtax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.03);
				oneShow.setText("二套非普通住宅，契税为总房价的3%");
			}

		}
		LogUtils.println("契税" + deedtax);
		price1.setText(StringHandleUtil.toOnlyHavaTwo(deedtax) + "");
		//营业税/综合地价款
		double salesTax = 0;
		if (houseType == 0) {//普通住宅
			twotitle.setText("营业税");
			if (houseLong == 0) {//房屋年限
				salesTax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.056);
				twoshow.setText("购房不满2年，营业税为总房价的5.6%");
			} else {
				salesTax = 0;
				twoshow.setText("购房满2年，营业税为0");
			}
		} else if (houseType == 1) {//非普通
			if (houseLong == 0) {//房屋年限
				salesTax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.056);
				twoshow.setText("购房不满2年，营业税为总房价的5.6%");
			} else {
				salesTax = 0;
				twoshow.setText("购房满2年，营业税为0");
			}
		}

		//经适房无营业税
		//综合地价款
		if (houseType == 2) {
			twotitle.setText("综合地价税");
			salesTax = StringHandleUtil.toOnlyTwo(nowprice * 10000 * 0.01);
			twoshow.setText("综合地价税为房屋总价的10%");
		}
		LogUtils.println("营业税" + salesTax);
		price2.setText(StringHandleUtil.toOnlyHavaTwo(salesTax) + "");
		//个人所得税
		double individualtax = 0;
		if (houseType == 0 || houseType == 1) {//非经济适用房
			if (houseLong == 2) {//满5年
				if (isOnlyBuy) {//是否唯一
					individualtax = 0;
					threeshow.setText("满5年且卖方唯一住房，个人所得税为0");
				} else {
					individualtax = StringHandleUtil.toOnlyTwo((nowprice - oldprice) * 10000 * 0.2);
					threeshow.setText("满5年但非卖方唯一住房，个人所得税为 (房屋现总价-房屋原价)*20%");
				}
			} else {
				individualtax = StringHandleUtil.toOnlyTwo((nowprice - oldprice) * 10000 * 0.2);
				threeshow.setText("房产证不满5年，个人所得税为(房屋现总价-房屋原价）*20%");
			}

		} else if (houseType == 2) {//经济适用房

			if (isOnlyBuy) {//是否唯一
				individualtax = 0;
				threeshow.setText("卖方家庭唯一住房，个人所得税为0");
			} else {
				individualtax = StringHandleUtil.toOnlyTwo((nowprice - oldprice) * 10000 * 0.2);
				threeshow.setText("卖方家庭不唯一住房，个人所得税为 (房屋现总价-房屋原价)*20%");
			}
		}

		LogUtils.println("个人所得税" + individualtax);
		price3.setText(StringHandleUtil.toOnlyHavaTwo(individualtax) + "");
		allHouseMoney.setText(StringHandleUtil.toOnlyHavaTwo(deedtax + salesTax + individualtax + 5) + "");
	}

	@Click(R.id.back)
	public void backClick() {
		this.finish();
	}
}
